package org.gingresosapi.persistencia;

import org.gingresosapi.beans.Vehiculostraspaso;
import java.sql.Date; 
import org.gingresosapi.beans.*;
import org.gingresosapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.gingresosapi.generales.Mensajeria;
import org.gingresosapi.generales.DataGManager;


/**
*
* @author
*/

public class VehiculostraspasoPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/gingresosapi/properties/mensajes");
static DataGManager dataGManager;
static List<Vehiculostraspaso> list;

public VehiculostraspasoPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Vehiculostraspaso vehiculostraspaso ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into vehiculostraspaso(idnumeraciontraspaso,idvehiculo,placa,idrecibo,idold,tipoidold,id,tipoid,activo,idmunicipio,fechatraspaso,fecha,username)  values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setInt(1,vehiculostraspaso.getIdnumeraciontraspaso());
        pinsert.setLong(2,vehiculostraspaso.getIdvehiculo());
        pinsert.setString(3,vehiculostraspaso.getPlaca());
        pinsert.setInt(4,vehiculostraspaso.getIdrecibo());
        pinsert.setString(5,vehiculostraspaso.getIdold());
        pinsert.setString(6,vehiculostraspaso.getTipoidold());
        pinsert.setString(7,vehiculostraspaso.getId());
        pinsert.setString(8,vehiculostraspaso.getTipoid());
        pinsert.setString(9,vehiculostraspaso.getActivo());
        pinsert.setString(10,vehiculostraspaso.getIdmunicipio());
        pinsert.setDate(11,vehiculostraspaso.getFechatraspaso());
        pinsert.setDate(12,vehiculostraspaso.getFecha());
        pinsert.setString(13,vehiculostraspaso.getUsername());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Vehiculostraspaso vehiculostraspaso ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update vehiculostraspaso set  idnumeraciontraspaso=?, idvehiculo=?, placa=?, idrecibo=?, idold=?, tipoidold=?, id=?, tipoid=?, activo=?, idmunicipio=?, fechatraspaso=?, fecha=?, username=?  where  idnumeraciontraspaso ='"+vehiculostraspaso.getIdnumeraciontraspaso()+"' and  idmunicipio ='"+vehiculostraspaso.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(1,vehiculostraspaso.getIdnumeraciontraspaso());
pupdate.setLong(2,vehiculostraspaso.getIdvehiculo());
pupdate.setString(3,vehiculostraspaso.getPlaca());
pupdate.setInt(4,vehiculostraspaso.getIdrecibo());
pupdate.setString(5,vehiculostraspaso.getIdold());
pupdate.setString(6,vehiculostraspaso.getTipoidold());
pupdate.setString(7,vehiculostraspaso.getId());
pupdate.setString(8,vehiculostraspaso.getTipoid());
pupdate.setString(9,vehiculostraspaso.getActivo());
pupdate.setString(10,vehiculostraspaso.getIdmunicipio());
pupdate.setDate(11,vehiculostraspaso.getFechatraspaso());
pupdate.setDate(12,vehiculostraspaso.getFecha());
pupdate.setString(13,vehiculostraspaso.getUsername());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  vehiculostraspaso set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Vehiculostraspaso vehiculostraspaso_old , Vehiculostraspaso vehiculostraspaso) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update vehiculostraspaso set  idnumeraciontraspaso=? ,  idmunicipio=?  where  idnumeraciontraspaso ='"+vehiculostraspaso_old.getIdnumeraciontraspaso()+"' and  idmunicipio ='"+vehiculostraspaso_old.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(1,vehiculostraspaso.getIdnumeraciontraspaso());pupdate.setString(10,vehiculostraspaso.getIdmunicipio());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Vehiculostraspaso vehiculostraspaso ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from vehiculostraspaso  where  idnumeraciontraspaso = ? and  idmunicipio = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setInt(1,vehiculostraspaso.getIdnumeraciontraspaso());
pdelete.setString(10,vehiculostraspaso.getIdmunicipio());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from vehiculostraspaso where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from vehiculostraspaso  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Vehiculostraspaso vehiculostraspaso) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from vehiculostraspaso where idnumeraciontraspaso='"+vehiculostraspaso.getIdnumeraciontraspaso()+"' and idmunicipio='"+vehiculostraspaso.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Vehiculostraspaso findByPrimaryKey(Vehiculostraspaso vehiculostraspaso) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from vehiculostraspaso where idnumeraciontraspaso='"+vehiculostraspaso.getIdnumeraciontraspaso()+"' and idmunicipio='"+vehiculostraspaso.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            vehiculostraspaso.setIdnumeraciontraspaso(rs.getInt("idnumeraciontraspaso"));
vehiculostraspaso.setIdvehiculo(rs.getLong("idvehiculo"));
vehiculostraspaso.setPlaca(rs.getString("placa"));
vehiculostraspaso.setIdrecibo(rs.getInt("idrecibo"));
vehiculostraspaso.setIdold(rs.getString("idold"));
vehiculostraspaso.setTipoidold(rs.getString("tipoidold"));
vehiculostraspaso.setId(rs.getString("id"));
vehiculostraspaso.setTipoid(rs.getString("tipoid"));
vehiculostraspaso.setActivo(rs.getString("activo"));
vehiculostraspaso.setIdmunicipio(rs.getString("idmunicipio"));
vehiculostraspaso.setFechatraspaso(rs.getDate("fechatraspaso"));
vehiculostraspaso.setFecha(rs.getDate("fecha"));
vehiculostraspaso.setUsername(rs.getString("username"));
    }
    rs.close();
    psquery.close();
 return vehiculostraspaso;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdnumeraciontraspaso()
*/

public static List<Vehiculostraspaso> findByIdnumeraciontraspaso(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where idnumeraciontraspaso='"+vehiculostraspaso.getIdnumeraciontraspaso()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdvehiculo()
*/

public static List<Vehiculostraspaso> findByIdvehiculo(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where idvehiculo='"+vehiculostraspaso.getIdvehiculo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByPlaca()
*/

public static List<Vehiculostraspaso> findByPlaca(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where placa='"+vehiculostraspaso.getPlaca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdrecibo()
*/

public static List<Vehiculostraspaso> findByIdrecibo(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where idrecibo='"+vehiculostraspaso.getIdrecibo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdold()
*/

public static List<Vehiculostraspaso> findByIdold(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where idold='"+vehiculostraspaso.getIdold()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTipoidold()
*/

public static List<Vehiculostraspaso> findByTipoidold(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where tipoidold='"+vehiculostraspaso.getTipoidold()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findById()
*/

public static List<Vehiculostraspaso> findById(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where id='"+vehiculostraspaso.getId()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTipoid()
*/

public static List<Vehiculostraspaso> findByTipoid(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where tipoid='"+vehiculostraspaso.getTipoid()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByActivo()
*/

public static List<Vehiculostraspaso> findByActivo(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where activo='"+vehiculostraspaso.getActivo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdmunicipio()
*/

public static List<Vehiculostraspaso> findByIdmunicipio(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where idmunicipio='"+vehiculostraspaso.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFechatraspaso()
*/

public static List<Vehiculostraspaso> findByFechatraspaso(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where fechatraspaso='"+vehiculostraspaso.getFechatraspaso()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFecha()
*/

public static List<Vehiculostraspaso> findByFecha(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where fecha='"+vehiculostraspaso.getFecha()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByUsername()
*/

public static List<Vehiculostraspaso> findByUsername(Vehiculostraspaso vehiculostraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
      String sql = "select * from vehiculostraspaso where username='"+vehiculostraspaso.getUsername()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Vehiculostraspaso> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Vehiculostraspaso>();
  String sql = "select * from vehiculostraspaso";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from vehiculostraspaso";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from vehiculostraspaso where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from vehiculostraspaso";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from vehiculostraspaso where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Vehiculostraspaso> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Vehiculostraspaso>();
  String sql = "select * from vehiculostraspaso where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Vehiculostraspaso> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Vehiculostraspaso>();
  String sql = "select * from vehiculostraspaso";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "vehiculostraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Vehiculostraspaso vehiculostraspaso2 = new Vehiculostraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idvehiculo"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(vehiculostraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
